import request from '@/config/axios'
import { defHttp } from '@/utils/http/axios';
import { RequestEnum } from '@/enums/httpEnum';
import { ServicePrefixEnum } from '@/enums/commonEnum';
import type { AxiosRequestConfig } from 'axios';

const MODULAR = '/system/tenant';

export const Api = {
  GetTenantPage: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/page`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  GetTenant: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/get`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  CreateTenant: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/create`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  UpdateTenant: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  DeleteTenant: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/delete`,
    method: RequestEnum.DELETE,
  } as AxiosRequestConfig,
}


// 查询租户列表
export const getTenantPage = (params: TenantPageReqVO) => {
  return defHttp.request({ ...Api.GetTenantPage,params})
}

// 查询租户详情
export const getTenant = (id: number) => {
  return defHttp.request({ ...Api.GetTenant,params:{id}})
}

// 新增租户
export const createTenant = (data: TenantVO) => {
  return defHttp.request({ ...Api.CreateTenant,params:data})
}

// 修改租户
export const updateTenant = (data: TenantVO) => {
  return defHttp.request({ ...Api.UpdateTenant,params:data})
}

// 删除租户
export const deleteTenant = (id: number) => {
  return defHttp.request({ ...Api.DeleteTenant,params: {id}})
}

export interface TenantVO {
  id: number
  name: string
  contactName: string
  contactMobile: string
  status: number
  domain: string
  packageId: number
  username: string
  password: string
  expireTime: Date
  accountCount: number
  createTime: Date
}

export interface TenantPageReqVO extends PageParam {
  name?: string
  contactName?: string
  contactMobile?: string
  status?: number
  createTime?: Date[]
}

export interface TenantExportReqVO {
  name?: string
  contactName?: string
  contactMobile?: string
  status?: number
  createTime?: Date[]
}

// // 查询租户列表
// export const getTenantPage = (params: TenantPageReqVO) => {
//   return request.get({ url: '/system/tenant/page', params })
// }
//
// // 查询租户详情
// export const getTenant = (id: number) => {
//   return request.get({ url: '/system/tenant/get?id=' + id })
// }
//
// // 新增租户
// export const createTenant = (data: TenantVO) => {
//   return request.post({ url: '/system/tenant/create', data })
// }
//
// // 修改租户
// export const updateTenant = (data: TenantVO) => {
//   return request.put({ url: '/system/tenant/update', data })
// }
//
// // 删除租户
// export const deleteTenant = (id: number) => {
//   return request.delete({ url: '/system/tenant/delete?id=' + id })
// }

// 导出租户 todo
export const exportTenant = (params: TenantExportReqVO) => {
  return request.download({ url: '/system/tenant/export-excel', params })
}
